# !/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName : zsj.py
# @Time     : 2024/4/14 19:39
# @Author   : Robot-Zsj
"""
description:

i:
5
5 15 40 30 10

o:
40 100 30 60 15 30 5 15 10
"""
import heapq


class Node:
    def __init__(self, lc, rc, weight, height):
        self.lc = lc
        self.rc = rc
        self.weight = weight
        self.height = height

    def __gt__(self, other):
        if self.weight != other.weight:
            return self.weight > other.weight
        else:
            return self.height > other.weight


n = int(input())
weights = list(map(int, input().split()))


def midOrder(root, seq):
    if root.lc is not None:
        midOrder(root.lc, seq)

    seq.append(root.weight)

    if root.rc is not None:
        midOrder(root.rc, seq)


def getResult():
    pq = []

    for w in weights:
        heapq.heappush(pq, Node(None, None, w, 0))

    while len(pq) > 1:
        lc = heapq.heappop(pq)
        rc = heapq.heappop(pq)

        fa_weight = lc.weight + rc.weight
        fa_height = max(lc.height, rc.height) + 1

        heapq.heappush(pq, Node(lc, rc, fa_weight, fa_height))

    root = heapq.heappop(pq)
    seq = []
    midOrder(root, seq)

    return " ".join(map(str, seq))


print(getResult())
